﻿//==============================================================================  
//Copyright (C) 2012-2015 9UN.ORG. All rights reserved. 
//GUID：5726c72f-088c-47d9-8033-c83b05edf3bc
//CLR Version: 4.0.30319.18033
//Code Author：Kevin Wang
//Contact：Email(Admin@9un.org),QQ(265382 or 74344)
//Filename：TestWordRender
//Namespace：PDFTest
//Functions：TestWordRender  
//Created by Kevin Wang at 2013/2/3 13:58:16 http://blog.9un.org
//============================================================================== 
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RuanRang.Core;
using RuanRang.Core.Common;
using RuanRang.Core.Render;

namespace PDFTest
{
    [TestClass]
    public class TestWordRender
    {
        /// <summary>
        /// Tests the load assembly.
        /// </summary>
        [TestMethod]
        public RenderPluginContainer TestLoadAssembly()
        {
            const string file = @"D:\Microsoft SkyDrive\SkyDrive\组件\word_pdf_Plugins\Plugins\WordsRender.dll";
            var assemblyContainer = new RenderPluginContainer();
            assemblyContainer.Register(RenderPluginType.Word, file);
            Assert.IsNotNull(assemblyContainer);
            return assemblyContainer;
        }

        /// <summary>
        /// Tests the load PDF.
        /// </summary>
        [TestMethod]
        public WordRender TestLoadword()
        {
            var render = TestLoadAssembly();
            var word = new WordRender(render);
            Assert.IsNotNull(word);
            const string pdfFile = @"H:\TFS_My Work\My Work\CourseToolSuite\Tools\LibTest\bin\Debug\2.docx";
            word.Open(pdfFile);
            word.OpenCompleted += (sender, args) => Trace.WriteLine("Open Async Completed");
            word.OpenAsync(pdfFile);
            Assert.IsNotNull(word.TargetFile);
            Trace.WriteLine("Page Count: " + word.PageCount);
            return word;
        }

        /// <summary>
        /// Tests the save image.
        /// </summary>
        [TestMethod]
        public void TestSaveImage()
        {
            var word = TestLoadword();
            word.Save(@"H:\TFS_My Work\My Work\CourseToolSuite\Tools\LibTest\bin\Debug\Test", "DOC", @"D:\My Icon\2756\2756\kuang.png",imageFormat:ImageFormat.Png);
        }

        /// <summary>
        /// Tests the get image.
        /// </summary>
        [TestMethod]
        public void TestGetImage()
        {
            var word = TestLoadword();
            //word.GetImageCompleted += (sender, args) =>
            //{
            //    var imgeArg = args as ImageEventArgs;
            //    Assert.IsNotNull(imgeArg);
            //    Assert.IsFalse(imgeArg.ImageDictionary.Count > 0);
            //    Trace.WriteLine("Get Image Async Completed");
            //};
            var img = word.GetImage(0);
            //word.GetImageAsync(0);
            Assert.IsNotNull(img);
            img.Dispose();
            img = null;
            Assert.IsNull(img);
        }
    }
}
